﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SnmpForm.ApBatchConfig
{
    public partial class FrmSyncStatus : FrmApBatchConfig
    {
        public FrmSyncStatus(List<BusinessWrapper.Ap> list)
            :base(list)
        {
            InitializeComponent();
        }

        public override BatchTask CreateTask(List<BusinessWrapper.Ap> aps)
        {
            return new BatchSyncTask(this, aps);
        }

        public override void UpdateStatusMethod(BusinessWrapper.Ap ap, string strStatus)
        {
            foreach (ListViewItem item in listViewStatus.Items)
            {
                int nApid = Convert.ToInt32(item.Text);
                if (nApid == ap.GetInfo().id)
                {
                    bool bChange =
                        !item.SubItems[2].Text.Equals(strStatus);
                    if (bChange)
                    {
                        item.SubItems[2].Text = strStatus;
                    }
                    break;
                }
            }
        }

        private void FrmSyncStatus_Load(object sender, EventArgs e)
        {
            //listView
            listViewStatus.View = View.Details;
            listViewStatus.FullRowSelect = true;
            listViewStatus.Columns.Add("id", 50);
            listViewStatus.Columns.Add("标示码", 130);
            listViewStatus.Columns.Add("状态", 150);
            UpdateViewStatus();

            StartApBatchTask();
        }

        private void UpdateViewStatus()
        {
            foreach (BusinessWrapper.Ap ap in m_listAsset)
            {
                ListViewItem lvi = new ListViewItem();

                DbWrapper.DbDataTypes.Ap apinfo = ap.GetInfo();
                lvi.Text = apinfo.id.ToString();
                lvi.SubItems.Add(apinfo.mark);
                lvi.SubItems.Add("等待");

                listViewStatus.Items.Add(lvi);
            }
        }

        private void FrmSyncStatus_FormClosing(object sender, FormClosingEventArgs e)
        {
            StopApBatchTask();
        }
    }
}
